package com.yilin.tms.user.controller;

import com.yilin.tms.core.application.PageData;
import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.annotation.Explain;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.core.entity.user.technical.GoodsConfigure;
import com.yilin.tms.core.entity.user.technical.LineConfigure;
import com.yilin.tms.user.service.IGoodsConfigureService;
import com.yilin.tms.user.service.ILineConfigureService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;


@RestController
@RequestMapping("/user/configure/")
public class ConfigureController extends BaseController {

    @Resource
    ILineConfigureService lineConfigureService;
    @Resource
    IGoodsConfigureService goodsConfigureService;


    /**
     * 编辑线路配置
     */
    @PostMapping(value = "editLineConfigure")
    public ReturnData<Object> editLineConfigure(LineConfigure lineConfigure) {
        lineConfigure.setUpdateUserId(getLoginUser().getId());
        lineConfigure.setUpdateTime(new Date());
        lineConfigureService.saveOrUpdateLineConfigure(lineConfigure);
        return jsonView(SUCCESS_CODE, "操作成功");
    }

    /**
     * 获取线路配置
     */
    @PostMapping(value = "getLineConfigure")
    public ReturnData<Object> getLineConfigure(String id) {
        if (id == null || id.isEmpty()) {
            return jsonView(FAIL_CODE, "ID为空");
        }
        LineConfigure lineConfigureById = lineConfigureService.getLineConfigureById(id);
        return jsonView(SUCCESS_CODE, "操作成功", lineConfigureById);
    }
    /**
     *  获取线路配置分页
     */
    @PostMapping(value = "getLineConfigurePage")
    public ReturnData<PageData<LineConfigure>> getLineConfigurePage(LineConfigure query, @Explain("页码") Integer page, @Explain("条数") Integer limit) {
        PageData<LineConfigure> pageData = lineConfigureService.getLineConfigurePage(getLoginUser(), query, page, limit);
        return jsonView(true, "获取成功", pageData);
    }
    /**
     * 编辑货物配置
     */
    @PostMapping(value = "editGoodsConfigure")
    public ReturnData<Object> editGoodsConfigure(GoodsConfigure goodsConfigure) {
        goodsConfigure.setUpdateUserId(getLoginUser().getId());
        goodsConfigure.setUpdateTime(new Date());
        goodsConfigureService.saveOrUpdateGoodsConfigure(goodsConfigure);
        return jsonView(SUCCESS_CODE, "操作成功");
    }
    /**
     *  获取货物配置分页
     */
    @PostMapping(value = "getGoodsConfigurePage")
    public ReturnData<PageData<GoodsConfigure>> getGoodsConfigurePage(GoodsConfigure query, @Explain("页码") Integer page, @Explain("条数") Integer limit) {
        PageData<GoodsConfigure> pageData = goodsConfigureService.getGoodsConfigurePage(getLoginUser(), query, page, limit);
        return jsonView(true, "获取成功", pageData);
    }
    /**
     * 获取货物配置
     */
    @PostMapping(value = "getGoodsConfigure")
    public ReturnData<Object> getGoodsConfigure(String id) {
        if (id == null || id.isEmpty()) {
            return jsonView(FAIL_CODE, "ID为空");
        }
        GoodsConfigure goodsConfigure = goodsConfigureService.getGoodsConfigureById(id);
        return jsonView(SUCCESS_CODE, "操作成功", goodsConfigure);
    }


}
